package com.zhongshengnetwork.rightbe.lang.model;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
//import android.support.v4.content.ContextCompat;
//import android.support.v4.view.PagerAdapter;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXTextObject;
import com.zhongshengnetwork.rightbe.Adv.model.AdvertUtils;
import com.zhongshengnetwork.rightbe.Adv.model.SPManageUtils;
import com.zhongshengnetwork.rightbe.Constant.APIKey;
import com.zhongshengnetwork.rightbe.Constant.Constant;
import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.BroadcastDefine;
import com.zhongshengnetwork.rightbe.common.CircleTransform;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.ScreenUtils;
import com.zhongshengnetwork.rightbe.common.TextUtil.DisplayUtils;
import com.zhongshengnetwork.rightbe.common.TextUtil.FontUitls;
import com.zhongshengnetwork.rightbe.common.TextUtil.ShowAllSpan;
import com.zhongshengnetwork.rightbe.common.TextUtil.ShowAllTextView;
import com.zhongshengnetwork.rightbe.common.TextUtil.VerticalTextView;
import com.zhongshengnetwork.rightbe.common.VerTextView;
import com.zhongshengnetwork.rightbe.common.customview.ActionSheetDialog;
import com.zhongshengnetwork.rightbe.common.customview.ShareDialog;
import com.zhongshengnetwork.rightbe.common.love.Love;
import com.zhongshengnetwork.rightbe.common.utils.ToastUtil;
import com.zhongshengnetwork.rightbe.gsonmodel.LangInfoModel;
import com.zhongshengnetwork.rightbe.https.HttpCallBack;
import com.zhongshengnetwork.rightbe.https.HttpsUtils;
import com.zhongshengnetwork.rightbe.lang.activity.CardViewActivity;
import com.zhongshengnetwork.rightbe.lang.activity.LangDetailActivity;
import com.zhongshengnetwork.rightbe.lang.res.Configs;
import com.zhongshengnetwork.rightbe.login.LoginActivity;
import com.zhongshengnetwork.rightbe.wzt.view.OnDoubleClickListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

/**
 * Created by luojingxing on 2018/10/29.
 */

public class CardViewAdapter extends PagerAdapter {

    public List<LangInfoModel> list;
    private Context context;
    private LayoutInflater inflater;

    //微信分享
    private List<String> nameList;
    private LangInfoModel langInfoModel = null;
    private CardViewActivity cardViewActivity;
    private int screenWidth = 0;
    private int screenHeight = 0;
    private int textHeight = 0;
    private int maxLine = 0;
    private int imgW  = 0;
    private int imgH = 0;

    private void writeComment(int position){
         if (cardViewActivity != null){
             cardViewActivity.writeComment(position);
         }
    }

    public CardViewAdapter(Context context, CardViewActivity activity) {
        this.context = context;
        cardViewActivity = activity;

        this.screenWidth = ScreenUtils.getScreenWidth(activity);
        this.screenHeight = ScreenUtils.getScreenHeight(activity);
        this.imgW = this.screenWidth;// - ScreenUtils.dip2px(context, 40);
        int height = Math.round(imgW / Configs.Value.IMAGE_WIDTH_HEIGHT_RATIO);
        this.imgH = height;

        this.textHeight = this.screenHeight - DisplayUtils.dp2px(activity, 240) - this.imgH; //180
        int textLineHeight = DisplayUtils.sp2px(activity, 16) + DisplayUtils.dp2px(activity, 8);
        this.maxLine = this.textHeight/textLineHeight;
        if (this.maxLine > 1){
            this.maxLine -= 1;
        }

        this.list = new ArrayList<LangInfoModel>();
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = inflater.inflate(R.layout.cardview_item, container, false);
        container.addView(view);
        Love cardview_item_layout = (Love) view.findViewById(R.id.cardview_item_layout);
        ImageView cardview_item_bg = (ImageView) view.findViewById(R.id.cardview_item_bg);
        ShowAllTextView textView = (ShowAllTextView) view.findViewById(R.id.banner_title);

        VerticalTextView banner_title_vertical = (VerticalTextView) view.findViewById(R.id.banner_title_vertical);
        RelativeLayout banner_title_vertical_layout = (RelativeLayout) view.findViewById(R.id.banner_title_vertical_layout);

        ImageView header = (ImageView) view.findViewById(R.id.banner_header);
        ImageView banner_img = (ImageView) view.findViewById(R.id.banner_img);
        LinearLayout banner_like_layout = (LinearLayout) view.findViewById(R.id.banner_like_layout);
        ImageView banner_like_icon = (ImageView) view.findViewById(R.id.banner_like_icon);
        TextView banner_like_count = (TextView) view.findViewById(R.id.banner_like_count);
        LinearLayout banner_collect_layout = (LinearLayout) view.findViewById(R.id.banner_collect_layout);
        ImageView banner_collect_icon = (ImageView) view.findViewById(R.id.banner_collect_icon);
        TextView banner_collect_count = (TextView) view.findViewById(R.id.banner_collect_count);
        LinearLayout banner_share_layout = (LinearLayout) view.findViewById(R.id.banner_share_layout);
        ImageView banner_share_icon = (ImageView) view.findViewById(R.id.banner_share_icon);
        TextView banner_share_count = (TextView) view.findViewById(R.id.banner_share_count);
        LinearLayout banner_comment_layout = (LinearLayout) view.findViewById(R.id.banner_comment_layout);
        ImageView banner_comment_icon = (ImageView) view.findViewById(R.id.banner_comment_icon);
        TextView banner_comment_count = (TextView) view.findViewById(R.id.banner_comment_count);
        LangInfoModel model = list.get(position);
        cardview_item_bg.setVisibility(View.GONE);

        if (imgW > 0 && imgH > 0){
            ViewGroup.LayoutParams params = banner_img.getLayoutParams();
            params.width = imgW;
            params.height = imgH;
            banner_img.setLayoutParams(params);

            params = header.getLayoutParams();
            params.width = imgH;
            params.height = imgH;
            header.setLayoutParams(params);

        }

        if (model.getImglist() != null && model.getImglist().size() > 0){
            header.setVisibility(View.INVISIBLE);
            banner_img.setVisibility(View.VISIBLE);
            //Glide.with(this.context).load(model.getImglist().get(0)).transform(new CircleTransform(this.context)).dontAnimate().into(header);
            if (this.context != null){
                Glide.with(this.context).load(model.getImglist().get(0)).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(banner_img);
                //Glide.with(this.context).load(model.getImglist().get(0)).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(cardview_item_bg);
            }
        }else {
            header.setVisibility(View.VISIBLE);
            banner_img.setVisibility(View.INVISIBLE);
            if (this.context != null){
                Glide.with(this.context).load(model.getHeader()).transform(new CircleTransform(this.context)).dontAnimate().into(header);
                //Glide.with(this.context).load(model.getHeader()).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(cardview_item_bg);
            }
        }

        if (this.maxLine > 0){
            textView.setMaxShowLines(this.maxLine);
        }else {
            textView.setMaxShowLines(FontUitls.getTextMaxLine(screenHeight, cardViewActivity));//这里根据手机屏幕做适配，默认10
        }
        textView.setMyText(model.getTitle());
        textView.setTag(position);
        textView.setClickable(true);
        textView.setFocusable(false);

        textView.setOnAllSpanClickListener(new ShowAllSpan.OnAllSpanClickListener() {
            @Override
            public void onClick(View widget) {
                //ToastUtil.show(context, "点击了更多");
                onClickComment((int)widget.getTag());
            }
        });

        if (model.getTitle().length() < Constant.PortDisplayLength && FontUitls.isPortDisplay(model.getTitle()) == true){
            textView.setVisibility(View.INVISIBLE);
            banner_title_vertical_layout.setVisibility(View.VISIBLE);
            banner_title_vertical.setText(FontUitls.formatPortDisplay(model.getTitle()));
        }else {
            textView.setVisibility(View.VISIBLE);
            banner_title_vertical_layout.setVisibility(View.INVISIBLE);
        }
        banner_title_vertical_layout.setTag(position);
        banner_title_vertical_layout.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.DoubleClickCallback() {
            @Override
            public void onDoubleClick(View v, MotionEvent event) {
                if (cardViewActivity.love_layout != null){
                    //cardViewActivity.love_layout.addLoveView(screenWidth/2,screenHeight/2);
                    onClickLike((int)v.getTag());
                }
            }
        }));
        banner_title_vertical.setTag(position);
        banner_title_vertical.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.DoubleClickCallback() {
            @Override
            public void onDoubleClick(View v, MotionEvent event) {
                if (cardViewActivity.love_layout != null){
                    //cardViewActivity.love_layout.addLoveView(screenWidth/2,screenHeight/2);
                    onClickLike((int)v.getTag());
                }
            }
        }));

        cardview_item_layout.setTag(position);
        cardview_item_layout.setClickable(true);
        cardview_item_layout.setFocusable(false);
        cardview_item_layout.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.DoubleClickCallback() {
            @Override
            public void onDoubleClick(View v, MotionEvent event) {
                if (cardViewActivity.love_layout != null){
                    //cardViewActivity.love_layout.addLoveView(screenWidth/2,screenHeight/2);
                    onClickLike((int)v.getTag());
                }
            }
        }));

        cardview_item_layout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                int p = (int)view.getTag();
                if (list == null || list.size() == 0){
                    return false;
                }
                if (p >= list.size()){
                    return false;
                }
                LangInfoModel model = list.get(p);
                CommonUtils.copy(cardViewActivity, model.getTitle(), model.isOriginal(), model.getLangid());

                /*
                boolean isOpen = SPManageUtils.getInstance(CustomApplication.mContext).getSPBoolean(AdvertUtils.MoveCommentKey, true);
                if (isOpen == true){
                    SPManageUtils.getInstance(CustomApplication.mContext).putSPBoolean(AdvertUtils.MoveCommentKey, false);
                    cardViewActivity.displayComment();
                    ToastUtil.show(cardViewActivity, "动态评论墙已关闭");
                }else {
                    SPManageUtils.getInstance(CustomApplication.mContext).putSPBoolean(AdvertUtils.MoveCommentKey, true);
                    cardViewActivity.displayComment();
                    ToastUtil.show(cardViewActivity, "动态评论墙已开启");
                }
                */
                return false;
            }
        });

        CardView cardview = (CardView) view.findViewById(R.id.cardview);
        cardview.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
        textView.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());


        LinearLayout comment_line = (LinearLayout) view.findViewById(R.id.comment_line);
        comment_line.setBackgroundColor(AppThemeUtils.getInstance().getCardBackgroundColor());
        RelativeLayout comment_layout = (RelativeLayout) view.findViewById(R.id.comment_layout);
        comment_layout.setBackgroundResource(AppThemeUtils.getInstance().getCommentBg());
        comment_layout.setClickable(true);
        comment_layout.setTag(position);
        comment_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                writeComment((int)view.getTag());
            }
        });
        TextView write_comment_text = (TextView) view.findViewById(R.id.write_comment_text);
        write_comment_text.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
        if (model.getCommentcount() == 0){
            write_comment_text.setText("抢沙发");
        }else {
            write_comment_text.setText("说点什么吧");
        }

        banner_like_layout.setTag(position);
        banner_like_layout.setClickable(true);
        banner_like_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickLike((int)v.getTag());
            }
        });

        banner_collect_layout.setTag(position);
        banner_collect_layout.setClickable(true);
        banner_collect_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickCollect((int)v.getTag());
            }
        });

        banner_share_layout.setTag(position);
        banner_share_layout.setClickable(true);
        banner_share_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickShare((int)v.getTag());
            }
        });

        banner_comment_layout.setTag(position);
        banner_comment_layout.setClickable(true);
        banner_comment_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickComment((int)v.getTag());
            }
        });

        banner_like_count.setText(CommonUtils.getDisplayCount(model.getLikecount()));
        /*
        if (model.getLikecount() == 0){
            if (model.getType() == 30 || model.getType() == 21){
                banner_like_count.setText("喜欢");
            }else if (model.getType() == 44){
                banner_like_count.setText("同感");
            }else {
                banner_like_count.setText("笔芯");
            }
        }
        */

        banner_collect_count.setText(CommonUtils.getDisplayCount(model.getCollectcount()));
        if (model.getCollectcount() == 0){
            //banner_collect_count.setText("收藏");
        }
        banner_share_count.setText(CommonUtils.getDisplayCount(model.getSharecount()));
        if (model.getSharecount() == 0){
            //banner_share_count.setText("分享");
        }
        banner_comment_count.setText(CommonUtils.getDisplayCount(model.getCommentcount()));
        if (model.getCommentcount() == 0){
            //banner_comment_count.setText("评论");
        }

        if (model.islike() == true){
            banner_like_icon.setImageResource(R.drawable.my_like_select);
            banner_like_count.setTextColor(ContextCompat.getColor(this.context,R.color.lightGreenColor));
        }else {
            banner_like_icon.setImageResource(R.drawable.my_like);
            banner_like_count.setTextColor(ContextCompat.getColor(this.context,R.color.defaultSmallFontColor));
        }
        if (model.iscollect() == true){
            banner_collect_icon.setImageResource(R.drawable.my_collect_select);
            banner_collect_count.setTextColor(ContextCompat.getColor(this.context,R.color.lightGreenColor));
        }else {
            banner_collect_icon.setImageResource(R.drawable.my_collection);
            banner_collect_count.setTextColor(ContextCompat.getColor(this.context,R.color.defaultSmallFontColor));
        }
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(Object object) {
         return POSITION_NONE;//更新数据
    }

    private void onClickItem(int position, View view){
        /*
        if (list == null || list.size() == 0){
            return;
        }
        LangInfoModel model = list.get(position);
        Intent intent = new Intent(this.context, LangDetailActivity.class);
        Bundle bundle=new Bundle();
        bundle.putSerializable("model", model);//序列化
        intent.putExtras(bundle);//发送数据
        this.context.startActivity(intent);
        */
        if (list == null || list.size() == 0){
            return;
        }
        if (position >= list.size()){
            return;
        }
        LangInfoModel model = list.get(position);
        Love cardview_item_layout = (Love) view;
        if (model.islike() == false){
            cardview_item_layout.addLoveView(this.screenWidth/2.0f, this.screenHeight/2.0f);
            onClickLike(position);
        }
    }

    private void onClickLike(int position){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(this.context,LoginActivity.class);
            this.context.startActivity(intent);
            return;
        }
        if (list == null || list.size() == 0){
            return;
        }
        if (position >= list.size()){
            return;
        }
        LangInfoModel model = list.get(position);
        if (model.islike() == true){//修改之一
            model.setIslike(false);
            if (model.getLikecount() > 0){
                model.setLikecount(model.getLikecount()-1);
            }
            list.set(position,model);
            notifyDataSetChanged();
            final HashMap<String, String> map = new HashMap<String, String>();
            map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
            map.put("id", model.getLangid());
            String url = "miniapp/"+"langappid"+"/canclelike.do";
            HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                @Override
                public void onSuccess(String data) {
                    Log.e("TAG","笔芯结果："+data);
                }

                @Override
                public void onError(String msg) {
                }
            });
            return;
        }
        if (cardViewActivity.love_layout != null){
            cardViewActivity.love_layout.addLoveView(screenWidth/2,screenHeight/2);
        }
        model.setIslike(true);
        model.setLikecount(model.getLikecount()+1);
        list.set(position,model);
        notifyDataSetChanged();

        final String langid = model.getLangid();
        new Thread(){
            @Override
            public void run() {
                super.run();
                final HashMap<String, String> map = new HashMap<String, String>();
                map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                map.put("id", langid);
                map.put(APIKey.typeKey,"1");
                map.put("answerid","0");
                String url = "miniapp/"+"langappid"+"/langcl.do";
                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                    @Override
                    public void onSuccess(String data) {
                    }

                    @Override
                    public void onError(String msg) {
                    }
                });
            }
        }.start();
    }

    private void onClickCollect(int position){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(this.context,LoginActivity.class);
            this.context.startActivity(intent);
            return;
        }
        if (list == null || list.size() == 0){
            return;
        }
        if (position >= list.size()){
            return;
        }
        LangInfoModel model = list.get(position);
        if (model.iscollect() == true){//修改二
            model.setIscollect(false);
            if (model.getCollectcount() > 0){
                model.setCollectcount(model.getCollectcount()-1);
            }
            list.set(position,model);
            notifyDataSetChanged();
            final HashMap<String, String> map = new HashMap<String, String>();
            map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
            map.put("id", model.getLangid());
            String url = "miniapp/"+"langappid"+"/cancleCollect.do";
            HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                @Override
                public void onSuccess(String data) {
                    Log.e("TAG","笔芯结果："+data);
                }

                @Override
                public void onError(String msg) {
                }
            });
            return;
        }
        Log.e("TAG","点击了收藏");

        model.setIscollect(true);
        model.setCollectcount(model.getCollectcount()+1);
        list.set(position,model);
        notifyDataSetChanged();

        final String langid = model.getLangid();
        new Thread(){
            @Override
            public void run() {
                super.run();
                final HashMap<String, String> map = new HashMap<String, String>();
                map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                map.put("sourceid", langid);
                map.put(APIKey.typeKey,"1");
                String url = "miniapp/"+"langappid"+"/addcollection.do";
                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                    @Override
                    public void onSuccess(String data) {
                        Log.e("TAG","收藏结果："+data);
                    }

                    @Override
                    public void onError(String msg) {
                    }
                });
            }
        }.start();

    }

    private void onClickComment(int position){
        if (list == null || list.size() == 0){
            return;
        }
        if (position >= list.size()){
            return;
        }
        LangInfoModel model = list.get(position);
        Intent intent = new Intent(this.context, LangDetailActivity.class);
        Bundle bundle=new Bundle();
        bundle.putSerializable("model", model);//序列化
        intent.putExtras(bundle);//发送数据
        this.context.startActivity(intent);
    }

    private void onClickShare(int position){

        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(cardViewActivity, LoginActivity.class);
            cardViewActivity.startActivity(intent);
            return;
        }

        if (list == null || list.size() == 0){
            return;
        }
        if (position >= list.size()){
            return;
        }
        LangInfoModel model = list.get(position);
        langInfoModel = model;

        Intent intent = new Intent(cardViewActivity, LangDetailActivity.class);
        Bundle bundle=new Bundle();
        bundle.putSerializable("model", model);//序列化
        bundle.putBoolean("share",true);
        intent.putExtras(bundle);//发送数据
        cardViewActivity.startActivity(intent);

        /*
        final ShareDialog shareDialog = new ShareDialog(this.context)
                .builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        shareDialog.friend_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享到朋友圈
                shareToWX(0,langInfoModel.getTitle());
            }
        });
        shareDialog.wx_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享给微信好友
                shareToWX(1,langInfoModel.getTitle());
            }
        });
        shareDialog.wb_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //微博
                CustomApplication.WbShareType = 1;
                CustomApplication.WbShareSourceId = langInfoModel.getLangid();
                CustomApplication.WbShareText = langInfoModel.getTitle();
                Intent mIntent = new Intent(BroadcastDefine.WeiBo_Share_Action);
                //发送广播
                cardViewActivity.sendBroadcast(mIntent);
            }
        });
        shareDialog.qq_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享到qq
                shareToQQ(0,"微句-言微句美，发现共鸣",langInfoModel.getTitle());
            }
        });
        shareDialog.zone_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //qq空间
                shareToQQ(0,"微句-言微句美，发现共鸣",langInfoModel.getTitle());
            }
        });
        shareDialog.show();
        */
    }


    //分享到qq
    private Bundle params;
    private void shareToQQ(int type,String title,String content){
        params = new Bundle();
        if (type == 0){//分享给QQ好友
            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
            params.putString(QQShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QQShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,"http://a.app.qq.com/o/simple.jsp?pkgname=com.zhongshengnetwork.rightbe");// 内容地址
            params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,"http://image.daydayrise.net/360@2x.png");// 网络图片地址
            params.putString(QQShare.SHARE_TO_QQ_EXT_INT, "");//其它附加功能
            CustomApplication.mTencent.shareToQQ(cardViewActivity, params, null);
        }else {
            //分享到QQ空间
            params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
            params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL,"http://a.app.qq.com/o/simple.jsp?pkgname=com.zhongshengnetwork.rightbe");// 内容地址
            ArrayList<String> imgUrlList = new ArrayList<>();
            imgUrlList.add("http://image.daydayrise.net/360@2x.png");
            params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL,imgUrlList);// 图片地址
            CustomApplication.mTencent.shareToQzone(cardViewActivity, params, null);
        }

    }

    //分享文字到微信
    private void shareToWX(int type, String title){

        WXTextObject textObject = new WXTextObject();
        textObject.text = title;

        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObject;
        msg.description = title;

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("text");
        req.message = msg;
        req.scene = type==0 ? SendMessageToWX.Req.WXSceneTimeline:SendMessageToWX.Req.WXSceneSession;
        CustomApplication.mWxApi.sendReq(req);

    }
    private String buildTransaction(final String type) {
        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
    }

}
